home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATETIME.SWG / 0019_TIMEFORM.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  1KB  |  41 lines

  1. {
  2. MIKE COPELAND
  3.  
  4. > I'm looking For some FAST routines to change seconds into a
  5. > readable format, (ie. H:M:S).
  6. > For instance, 8071 seconds = 2:14:31
  7.  
  8.    Here's the code I use, and it's fast enough For me:
  9. }
  10.  
  11. Type
  12.   Str8 = String[8];
  13.  
  14. Function FORMAT_TIME (V : Integer) : STR8; { format time as hh:mm:ss }
  15. Var
  16.   X, Z  : Integer;
  17.   PTIME : STR8;
  18. begin                            { note: incoming time is in seconds }
  19.   Z := ord('0');
  20.   PTIME := '  :  :  ';           { initialize }
  21.   X := V div 3600;
  22.   V := V mod 3600;               { process hours }
  23.   if (X > 0) and (X <= 9) then
  24.     PTIME[2] := chr(X+Z)
  25.   else
  26.   if X = 0 then
  27.     PTIME[3] := ' '              { zero-suppress }
  28.   else
  29.     PTIME[2] := '*';             { overflow... }
  30.   X := V div 60;
  31.   V := V mod 60;                 { process minutes }
  32.   PTIME[4] := chr((X div 10)+Z);
  33.   PTIME[5] := chr((X mod 10)+Z);
  34.   PTIME[7] := chr((V div 10)+Z); { process seconds }
  35.   PTIME[8] := chr((V mod 10)+Z);
  36.   FORMAT_TIME := PTIME
  37. end;  { FORMAT_TIME }
  38.  
  39. begin
  40.   Writeln(Format_Time(11122));
  41. end.